<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>后台管理</title>
    <link rel="stylesheet" href="__PUBLIC__/admin/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="__PUBLIC__/admin/bootstrap/css/main.css">
    <link rel="stylesheet" href="__PUBLIC__/admin/uploadify/uploadify.css">
</head>

<body>
<!-- navbar -->
<include file="Application/Admin/View/common/header.html"/>
<!-- 菜单部分 -->
<include file="Application/Admin/View/common/rg_menu.html"/>
<div class="content">
    <div class="container-fluid">
        <div id="pad-wrapper">
            <div class="table-wrapper products-table section">
                <div class="row-fluid head">
                    <div class="span12">
                        <h4>新闻列表</h4>
                    </div>
                </div>
                <div class="row-fluid filter-block">
                    <div class="pull-right">
                        <a class="btn-flat success new-product"  data-toggle="modal" data-target="#myModal">+ 新增产品</a>
                    </div>
                </div>
                <div class="row-fluid">
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th>
                                名称
                            </th>
                            <th>
                                类别
                            </th>
                            <th>
                                简介
                            </th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <foreach item="categoryInfo" name="categoryInfoList">
                           <tr>
                              <td>{$categoryInfo.title}</td>
                              <td>{$categoryInfo.cate_name}</td>
                              <td>{$categoryInfo.content}</td>
                              <td><a href="{:U('News:deleteCategoryInfo')}?id={$categoryInfo.id}">删除</a></td>
                           </tr>
                        </foreach>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 新增模态框开始 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">新增新闻分类</h4>
            </div>
            <div class="modal-body">
                <form id="subform">
                    <div class="form-group">
                        <label for="mingtitle">名称</label>
                        <input type="text" name="title" class="form-control" id="mingtitle" placeholder="名称">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail1">分类名称</label>

                        <select name="cateId" id="exampleInputEmail1">
                            <foreach name="categoryList" item="category">
                               <option value="{$category.id}">{$category.cate_name}</option>
                            </foreach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="contentImgUrl">上传图片</label>
                        <input type="file" name="imgUrl1" id="contentImgUrl" multiple>
                        <img id="shagimg" class="img-responsive" alt="Responsive image">
                        <input type="hidden" id="imgll" name="imgUrl">
                    </div>
                    <div class="form-group">
                        <label for="contentIn">内容</label>
                        <textarea class="form-control" id="contentIn" name="content" placeholder='内容' ></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="btnsubmint">保存</button>
            </div>
        </div>
    </div>
</div>
<!-- 新增模态框结束 -->
<!-- end navbar -->
<script src="__PUBLIC__/admin/bootstrap/js/jquery-latest.js"></script>
<script src="__PUBLIC__/admin/bootstrap/js/bootstrap.min.js"></script>
<script src="__PUBLIC__/admin/uploadify/jquery.uploadify.js"></script>
<script>
    var baseth = '__ROOT__';
    $(function() {
        $('#contentImgUrl').uploadify({
            'buttonClass' : 'some-class',
            'buttonText':'上传图片',
            'swf'      : '__PUBLIC__/admin/uploadify/uploadify.swf',
            'uploader' : "{:U('News:upload')}",
            'onUploadSuccess' : function(file, data, response) {
               var data1=  $.parseJSON(data);
               if(data1.success == '0'){
                   alert('上传成功');
                   $("#shagimg").attr('src',baseth+data1.imgurl);
                   $("#imgll").val(data1.imgurl);
               }else{
                   alert('上传失败');
               }
            }
        });

        $("#btnsubmint").click(function(){
            var dataF =   $('#subform').serialize();
            $.post("{:U('addCategoryInfo')}",dataF,function(data){

                if(data.success == '1'){
                    window.location.reload();
                }


            });


        });
        $('#myModal').on('shown.bs.modal', function () {
            $('#subform').reset();
        })
    });

</script>
</body>

</html>
